package io.xxx.omni.oss.custom

import com.google.gson.JsonObject
import io.xxx.omni.oss.core.PageSynchronizer
import io.xxx.omni.oss.sdk.TxhjClient

/**
 * 腾讯汇聚
 */
// https://lingshou.qq.com/docs/business/
abstract class TxhjSynchronizer : PageSynchronizer<JsonObject>() {

    protected abstract val path: String

    override fun getResponse(context: Context, pageNo: Int, containsTotal: Boolean): JsonObject {
        val request = buildRequest(context, pageNo)
        val client = applicationContext.getBean(TxhjClient::class.java)
        val response = client.execute(store, path, request)
        if (response["code"].asInt != 0) {
            throwException(context, request, response)
        }
        return response["data"].asJsonObject
    }

    override fun getCount(context: Context, response: JsonObject): Int {
        return response["totalCount"].asInt
    }

    protected abstract fun buildRequest(context: Context, pageNo: Int): Map<String, Any>
}